<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let xhr;
    if(window.XMLHttpRequest) {
      xhr = new XMLHttpRequest()
    } else {
      xhr = new ActiveXObject('Microsoft.XMLHTTP')
    }

    console.log(xhr.readyState) // 0

    xhr.open('GET', 'http://localhost:2233/getUser', true)
    xhr.send()

    // xhr.setRequestHeader('Content-type', 'application/x-www-from-urlencoded')
    // xhr.send('state=1&flag=1') // POST 必须字符串，用&链接

    console.log(xhr.readyState) // 1


    xhr.onReadyStateChange = function () {
    console.log(xhr.readyState) // 2, 3 ,4

      if(xhr.readyState === 4 && xhr.state === 200) {
        console.log(1)
      }
    }
  </script>
</body>
</html>